package com.demo.lambda;

import java.util.concurrent.RecursiveTask;

public class FibonacciForkJoinTask extends RecursiveTask<Integer> {

	private final int end;

	FibonacciForkJoinTask(int end) {this.end = end;}

	@Override
	public Integer compute() {
		if (end <= 1) return end;
		FibonacciForkJoinTask f1 = new FibonacciForkJoinTask(end - 1);
		FibonacciForkJoinTask f2 = new FibonacciForkJoinTask(end - 2);
		return f2.compute() + f1.fork().join();
	}
}
